/**
 * 
 */
package com.sci.web.action.datareportseason.innovatebase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.sci.web.action.util.BaseAction;
import com.sci.web.bean.Enterprise_Funds;
import com.sci.web.dao.DataReportM_InnovateBaseDao;

/**
 * @author  BaiFuyou
 * @date: Nov 7, 2011 5:59:38 PM
 * 获取全部的该用户下面的资金投入强度数据
 */
public class GetInnovateBaseData_ResearchMoneyAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5068733286215828566L;
	@Resource
	private DataReportM_InnovateBaseDao dataReportM_InnovateBaseDao;
	private int uid;
	private int type;
	private String year;
	/**
	 * @return the uid
	 */
	public int getUid() {
		return uid;
	}
	/**
	 * @param uid the uid to set
	 */
	public void setUid(int uid) {
		this.uid = uid;
	}
	/**
	 * @return the type
	 */
	public int getType() {
		return type;
	}
	/**
	 * @param type the type to set
	 */
	public void setType(int type) {
		this.type = type;
	}
	/**
	 * @return the year
	 */
	public String getYear() {
		return year;
	}
	/**
	 * @param year the year to set
	 */
	public void setYear(String year) {
		this.year = year;
	}
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		int eid = dataReportM_InnovateBaseDao.getEnterpriseBaseId(uid);
		super.setContentType(super.JSON);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("eid", eid);map.put("whichyear", year);map.put("type", type);
		List<Enterprise_Funds> list = dataReportM_InnovateBaseDao.getAllEnterprise_FundsforPageLoad(map);
		StringBuffer sb = new StringBuffer("{");
		if(list.size() != 0 && list != null){
			sb.append(getJsonStr(list.get(0),"f"));
			sb.append(getJsonStr(list.get(1), "s"));
			sb.append(getJsonStr(list.get(2), "t"));
			sb.append("'funds_intensity':'"+list.get(0).getFunds_intensity()+"',");
			sb.append("'u_i':'1'}");
		}else{
			sb.append(getJsonStr(null,"f"));
			sb.append(getJsonStr(null, "s"));
			sb.append(getJsonStr(null, "t"));
			sb.append("'funds_intensity':'1',");
			sb.append("'u_i':'-1'}");
		}
		System.out.println(sb.toString());
		super.outPrint(sb.toString());
		return "json";
	}
	public String getJsonStr(Enterprise_Funds ef,String f){
		String s = "";
		if(f.equals("f")){
			s = "f_";
		}else if(f.equals("s")){
			s = "s_";
		}else if(f.equals("t")){
			s = "t_";
		}
		StringBuffer sb = new StringBuffer("");
		if(ef != null){
		sb.append("'"+s+"id':'"+ef.getFunds_id()+"','");
		sb.append(s+"sale':'"+ef.getFunds_income()+"','");
		sb.append(s+"invest':'"+ef.getFunds_base_investment()+"','");
		sb.append(s+"tech':'"+ef.getFunds_technology_investment()+"','");
		sb.append(s+"research':'"+ef.getFunds_research_investment()+"','");
		sb.append(s+"p':'"+ef.getFunds_ratio()+"',");
		}else{
			sb.append("'"+s+"id':'"+"','");
			sb.append(s+"sale':'"+"','");
			sb.append(s+"invest':'"+"','");
			sb.append(s+"tech':'"+"','");
			sb.append(s+"research':'"+"','");
			sb.append(s+"p':'"+"',");
		}
		return sb.toString();
	}
	
}
